<template>
	<view class="content">
		<!-- <view style="width: 100%; padding: 30rpx; display: flex; justify-content: space-between; background-color: #fa341b">
			<image @click="fh" style="width: 20rpx; height: 38rpx; margin-top: 8rpx" src="../../../static/fanhui.png"></image>
			<p style="color: #ffffff; font-size: 36rpx">邀请好友</p>
			<p></p>
		</view> -->
		<!-- <view style="position: absolute; top: 140rpx; z-index: 2">
			<image style="width: 500rpx; height: 90rpx; margin-left: 120rpx" src="../../../static/yaoqing_wezhi.png"></image>
		</view> -->
		
		<image class="img-top" src="../../../static/yq_top.png" mode=""></image>
		<div class="div-bottom">
			<image class="img-bottom" src="../../../static/yq_bottom.png" mode=""></image>
			<div class="bottom-po">
				<div class="div-code">邀请码: {{ data1.push }}</div>
				<div class="code-img-body" style="position: relative; height: height: 480rpx;">
					<image class="img-tf" src="../../../static/tf.png" mode=""></image>
					<view class="code-img" id="qrcCanvas" ><ayQrcode ref="qrcode" id="qrcCanvas" :modal="modal_qr" :url="url" @hideQrcode="hideQrcode" /></view>
				</div>
			</div>
		</div>
		
	
		<div class="page-bottom">
			<view style="width: 450rpx; height: 60rpx; margin-top: 20rpx; display: flex">
				<p style="color: #333333; font-size: 24rpx; font-weight: bold; line-height: 60rpx">请输入您的抽成比例:</p>
				<input
					type="number"
					placeholder="请输入抽成比例"
					v-model="data.bili"
					style="font-size: 24rpx; margin-top: 14rpx; width: 170rpx; border-bottom: 1rpx solid #999999; padding-left: 10rpx"
				/>
				<p style="margin-top: 16rpx">%</p>
			</view>

			<view
				style="font-weight: 600; width: 450rpx; height: 60rpx; background-color: #fff; color: #000; text-align: center; line-height: 60rpx; margin-top: 40rpx; border-radius: 10rpx"
				v-clipboard:copy="url"
				v-clipboard:success="copy"
				@click="dianji"
			>
				生成二维码 复制分享
			</view>
		</div>

		<!-- <view class="code-img" id="qrcCanvas" v-if="show"> -->

		<view class="img-body" style="position: absolute; top: 350rpx; left: 60rpx; width: 620rpx; height: 810rpx; background-color: #ffffff; border-radius: 10rpx">
			<image style="position: absolute; top: -80rpx; left: 240rpx; z-index: 2; width: 160rpx; height: 160rpx" :src="data1.picture" mode=""></image>
			<p style="font-size: 24rpx; margin-top: 60rpx; margin-left: 280rpx; color: #333333">邀请码</p>
			<p style="width: 200rpx; height: 60rpx; margin: auto; text-align: center; line-height: 60rpx; font-size: 48rpx; color: #333333">{{ data1.push }}</p>
			<!-- <image style="width:360rpx;height:360rpx;margin-top: 30rpx;margin-left: 120rpx;" src="../../../static/ma.png"></image> -->
		</view>
	</view>
</template>

<script>
import ayQrcode from '../../../components/ay-qrcode/ay-qrcode.vue';
export default {
	components: {
		ayQrcode,
	},
	data() {
		return {
			show: false,
			data1: {},
			modal_qr: false,
			url: '', // 要生成的二维码值
			data: {
				bili: '10',
			},
		};
	},
	onLoad() {
		let id = uni.getStorageSync('uid');
		this.getInvitationCd();
	},
	methods: {
		preview(){
			console.log('1111 :>> ', 1111);
			uni.previewImage({
				urls:[this.url],
				longPressActions: {
					itemList: ['发送给朋友', '保存图片', '收藏'],
					success: function(data) {
						console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
					},
					fail: function(err) {
						console.log(err.errMsg);
					}
				}
			});
		},
		dianji() {
			this.show = true;
			this.url = 'https://jizhuan6688.com/#/pages/index/me/yaoqing_zuce?id=' + uni.getStorageSync('uid');

			if (this.data.bili >= 1 && this.data.bili <= 100) {
				var res = /^[1-9]\d*$/;
				if (!res.test(this.data.bili)) {
					//this.data.bili = '';
					return uni.$showMsg('请输入正确的比例!');
				}

				this.url = `${this.url}&bili=` + this.data.bili + '&iCd=' + this.data1.push;
				this.showQrcode();
				console.log('this.url :>> ', this.url);
				var _this = this;
				setTimeout(function() {
					console.log('this.url :>> ', 111);
					//_this.data.bili = '';
					// _this.url =
					// 	'https://jizhuan6688.com/#/pages/index/me/yaoqing_zuce?id=' +
					// 	uni.getStorageSync('uid');
				}, 1000);
			}

			if (!this.data.bili) {
				this.url = `${this.url}&bili=` + 10 + '&iCd=' + this.data1.push;
				this.showQrcode();
				console.log('this.url :>> ', this.url);
				var _this = this;
				setTimeout(function() {
					console.log('this.url :>> ', 111);
					//_this.data.bili = '';
				}, 1000);
			}
		},
		copy(e) {
			if (!this.data.bili || this.data.bili > 100 || this.data.bili < 1) {
				this.data.bili = '';
			} else {
				uni.$showMsg('复制已成功请分享!');
			}
		},
		onError(e) {
			console.log(e);
		},
		// rakeRt() {

		// 	if (!this.data.push) return uni.$showMsg('暂无邀请码!');
		// 	if (this.data.bili >= 1 && this.data.bili <= 100) {

		// 		this.url = `${this.url}&bili=` + this.data.bili +'&iCd='+this.data.push ;
		// 		console.log('this.url :>> ', this.url);
		// 	} else {
		// 		uni.$showMsg('请正确的输入比例!');
		// 	}
		// },
		// 展示二维码
		showQrcode() {
			let _this = this;
			this.modal_qr = true;
			// uni.showLoading()
			setTimeout(function() {
				// uni.hideLoading()
				_this.$refs.qrcode.couponQrCode();
			}, 50);
		},

		//传入组件的方法
		hideQrcode() {
			this.modal_qr = false;
		},
		fh() {
			wx.switchTab({
				url: '../me_a',
			});
		},

		async getInvitationCd() {
			let obj = {
				uid: uni.getStorageSync('uid'),
			};
			const res = await this.$u.post('api/user/invite_friends', obj, {});
			if (!res.code) uni.$showMsg();
			this.data1 = res.data;
			this.url = `https://jizhuan6688.com/#/pages/index/me/yaoqing_zuce?bili=10&iCd= ${this.data1.push}`;
			let that = this;
			//that.showQrcode(); //一加载生成二维码
			console.log('res >>  ', res);
		},
	},
};
</script>

<style lang="scss">
.content {
	width: 100%;
	height: 100vh;
	position: relative;
	background-color: #ff8d8d;
	overflow: hidden;

	.yaoqing-bejing {
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		z-index: -1;
	}

	.img-top {
		width: 100%;
	}

	.div-bottom {
		width: 100%;
		position: relative;
		margin-top: -8rpx;

		.img-bottom {
			position: absolute;
			left: 0;
			top: 0;
			width: 100%;
			z-index: 0;
		}

		.bottom-po {
			position: absolute;
			left: 0;
			top: 0;
			width: 100%;
			z-index: 2;
		}

		.code-img-body {
			position: relative;
			height: 480rpx;
		}

		.img-tf {
			width: 460rpx;
			position: absolute;
			left: 50%;
			top: -10px;
			transform: translateX(-50%);
		}

		.code-img {
			
			width: 100%;
			height: 100%;
			position: absolute;
			// left: 50%;
			// top: 120rpx;
			top:  25%;
			left: 51%;
			transform: translateX(-50%);
			
		}

		.div-code {
			width: 60%;
			margin: 0 auto;
			padding: 15rpx 30rpx;
			background-color: #f5701d;
			color: #fff;
			font-weight: bold;
			text-align: center;
		}
	}
}

/deep/canvas {
	// width: 120rpx !important;
	// height: 120rpx !important;
}

.page-bottom {
	position: absolute;
	bottom: 60rpx;
	left: 50%;
	transform: translateX(-50%);
	z-index: 10;
}

.img-body {
	display: none;
}

#qrcCanvas {
	width: 240rpx !important;
	height: 240rpx !important;
	overflow: hidden;
}

uni-canvas {
	width: 240rpx !important;
	height: 240rpx !important;

	& > canvas {
		width: 240rpx !important;
		height: 240rpx !important;
	}
}
</style>
